
/*******************************************************************************
 * url.hpp - an url handler library 
 * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 ******************************************************************************/

#ifndef __BOCAT_COMMON_URL_HPP_2010__
#define __BOCAT_COMMON_URL_HPP_2010__

#include <stdexcept>
#include <string>
#include <iostream>

namespace bocat {
namespace common {


class URL
{
public:
        URL() { port = 80; }
        URL(const std::string& url);
        URL(const std::string& address, unsigned port, const std::string& path);
        virtual ~URL() {}

        std::string getURL( void );
		std::string getSchema( void ) { return schema; }
        std::string getHostName( void )   { return host; }
        unsigned getPort( void )      { return port; }
        std::string getPath( void )   { return path; }

		std::string	getReversedHostName( void );
		std::string	getReversedURL( void );

        void setURL(const URL& url);
        void setURL(const std::string& url);
		void setSchema(const std::string& schema) { this->schema = schema; }
        void setHostName(const std::string& host) { this->host = host; }
        void setPort(unsigned port) { this->port = port; }
        void setPath(const std::string& path);

        bool empty() { return host == "" || path == ""; }

		
		static bool	isURL( const std::string& str );
		static bool	isURL( const char * str );
		
// friends:
        friend std::ostream& operator<<(std::ostream& os, URL& data);

private:
		std::string schema;
        std::string host;
        unsigned port;
        std::string path;


};	// class URL

std::string getLink(std::string link, URL& url);

}	// namespace common
}	// namespace bocat

#endif /* __BOCAT_COMMON_URL_HPP_2010__*/

